package com.happy_lab_management.demo.admin.labSchedule.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.happy_lab_management.demo.admin.labSchedule.mapper.LabScheduleMapper;
import com.happy_lab_management.demo.admin.labSchedule.service.LabScheduleService;
import com.happy_lab_management.demo.technician.lab.service.LabService;
import com.happy_lab_management.entity.DTO.ScheduleDTO;
import com.happy_lab_management.entity.ExperimentApplication;
import com.happy_lab_management.entity.Lab;
import com.happy_lab_management.entity.LabSchedule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("adminLabScheduleService")
public class LabScheduleServiceImpl extends ServiceImpl<LabScheduleMapper, LabSchedule> implements LabScheduleService {
    @Autowired
    private LabScheduleMapper labScheduleMapper;
    public boolean isLabFree(Lab lab, ExperimentApplication experimentApplication) {
        QueryWrapper<LabSchedule> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("lab_id", lab.getId())
                .eq("semester_id", experimentApplication.getSemesterId())
                .eq("section", experimentApplication.getSection())
                .eq("weekday", experimentApplication.getWeekday())
                .gt("end_week", experimentApplication.getStartWeek())  // 已排课的结束周大于申请的起始周
                .lt("start_week", experimentApplication.getEndWeek());  // 已排课的起始周小于申请的结束周

        return labScheduleMapper.selectCount(queryWrapper) == 0;
    }

}
